
package com.service.impl;


import java.util.List;
import java.util.Map;

import com.dao.UserMapper;
import com.model.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dao.UserDao;
import com.entity.UserEntity;
import com.service.UserService;
import com.utils.PageUtils;
import com.utils.Query;

import javax.annotation.Resource;


/**
 * 系统用户
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

	@Resource
	private UserMapper userMapper;

	@Override
	public List<UserEntity> selectListView(Wrapper<UserEntity> wrapper) {
		return baseMapper.selectListView(wrapper);
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params,
			Wrapper<UserEntity> wrapper) {
		 Page<UserEntity> page =new Query<UserEntity>(params).getPage();
	        page.setRecords(baseMapper.selectListView(page,wrapper));
	    	PageUtils pageUtil = new PageUtils(page);
	    	return pageUtil;
	}

	@Override
	public UserInfo getUserByName(String name) {
		return userMapper.findUserByName(name);
	}

	@Override
	public Integer findCount(String name) {
		return userMapper.findCount(name);
	}

	@Override
	public List<UserInfo> findUsers(String name, Integer pageIndex, Integer pageSize) {
		return userMapper.findUsers( name, (pageIndex - 1) * pageSize, pageSize);
	}

	@Override
	public void delUser(List<Long> ids) {
		userMapper.deleteUser(ids);
	}

	@Override
	public List<UserInfo> getAllTeacher() {
		return userMapper.findAllTeacher();
	}

	@Override
	public void updateUserInfo(Long id, String username, String password) {
		if (StringUtils.isNotEmpty(password)) {
			userMapper.updatePassword(id, username, password);
		} else {
			userMapper.updateName(id, username);
		}
	}

	@Override
	public void saveUser(UserInfo userInfo) {
		userMapper.insertUser(userInfo);
	}

	@Override
	public UserInfo getUserById(Long id) {
		return userMapper.findUserById(id);
	}

	@Override
	public void updateUser(UserInfo userInfo) {
		userMapper.updateUser(userInfo);
	}
}
